<?php
include_once("../include/init.php");
if(!isset($_SESSION['goods'])){
	msg("请添加商品",'index.php');
	exit;
}
$sql = "select * from tk_product";
$res = mysql_query($sql);
$info = [];
if(mysql_num_rows($res)>0){
	while($list = mysql_fetch_assoc($res)){
		$info[] =$list;
	}
}

?>

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>首页</title>
		<link rel="stylesheet" href="../public/css/index.css" />
	<link rel="stylesheet" href="../public/css/order.css">
		<style>
		#c1{
			width:20px;
			height:20px;
			background:black;
			display:inline-block;
		}
		#c2{
			width:20px;
			height:20px;
			background:pink;
			display:inline-block ;
}
</style>

	</head>
	<body>
		<!-- 头部-->
<?php
include_once("header.php");
?>
		<!-- 主体-->
		<div class="main">
			<form action="do_order.php "method="post"  id="form">
			<div class="addr">
				<div class="goods"><h4>收货信息</h4></div>				
				<table  cellpadding="0px" cellspacing="0px">
					<tr>
						<td><span>*</span>详细地址：</td>
						<td><input type="text" name="addr" id="addr" value="" /></td>
					</tr>
					<tr>
						<td><span>*</span>收&nbsp;货&nbsp;人&nbsp;：</td>
						<td><input type="text" name="user" id="user" value="" /></td>
					</tr>
					<tr>
						<td><span>*</span>手&nbsp;机&nbsp;号&nbsp;：</td>
						<td><input type="text" name="tel" id="tel" value="" /><span id="Sptel"></td>
					</tr>
				</table>
			 </div>
			<div class="addr">
				<div class="goods"><h4>送货清单</h4> <div class="result"><a href="cart.php">返回购物车</a></div></div>
					 
				<div class="clearfix"></div>
				<table border="1px" cellpadding="0px" cellspacing="0px" width="590px">
					<th>商品名称</th>
					<th>单价</th>
					<th>颜色</th>
					<th>容量</th>
					<th>数量</th>
					<th>小计</th>
					<?php 
					$sum=0;
					if(isset($_SESSION['goods'])){
						foreach($_SESSION['goods'] as $vo){
							foreach($info as $v){
							if($vo['pid'] == $v['pid']){
								$price = $v['price']*$vo['num'];
								$sum+=$price;																
					?>

					<tr>
						<td><?= $v['pname']?><img src="<?=$v['thumb']?>"width="50px" alt=""></td>
						<td>￥<?=$v['price']?>.00</td>
						<td>
								<?php
							if($vo['color']=='black'){
								echo"<div id='c1'></div>";
							}elseif($vo['color']=='pink'){
								echo"<div id='c2'></div>";
							}
								?></td>
						<td><?=$vo['size']?></td>
						<td><?=$vo['num']?></td>
						<td>￥<?=$price?>.00</td>
					</tr>
					<?php }}}}?>
				</table>
			
				<div class="sum"> 总计：<span>￥</span><?= $sum?></div>
				<div class="clearfix"></div>
				<input type="hidden" name="sum" value="<?= $sum?>">
				<input type="hidden" name="uid" value="<?= $vo['uid']?>">
				<div  class="right"> <input type="submit" name="sub" value="提交订单" class="input"></div>
			</form>
			 </div>			 
		</div>	
				<div class="clearfix"></div>
			<hr>
		<div class="clearfix"></div>
			<!-- 页脚-->
			<?php
             include_once("footer.php");
             ?>
		
	</body>
</html>
<script>
	var form = document.getElementById('form');
	var addr = document.getElementById('addr');
	var user = document.getElementById('user');
	var tel = document.getElementById('tel');
	var p3  =document.getElementById('Sptel');
		form.onsubmit=function(){
		var msg ="";
		var addr =addr.value;
		if(addr ==''){
			msg = '详细地址不能为空';
		}
		var user = user.value;
		if(user ==''){
			msg = '收货人不能为空';
		}
		var tel = tel.value;
		if(tel ==''){
			msg = '手机号不能为空';
		}
		if(msg ==''){
			return true;
		}else{
			alert(msg);
			return false;
		}
	}
	function regIsPhone() { 
			var code =/13[123569]{1}\d{8}|15[1235689]\d{8}|188\d{8}/;
			var str  = tel.value;
			if(code.test(str)){
				p3.innerHTML ="手机格式正确";
				p3.style.color ='#66ffff';
			}else{
				p3.innerHTML = '手机格式错误';
				p3 .style.color = '#ff0066';
			}
		}
		tel.onblur = regIsPhone;
		tel.onfocus = function(){
			p3.innerHTML="";
		}


</script>